package com.yanqu.road.server.manger.activity.dafuweng;

import com.yanqu.road.entity.activity.dafuweng.*;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.activity.dafuweng.eDaFuWengCardType;
import com.yanqu.road.entity.enums.activity.dafuweng.eDaFuWengEventType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eServerState;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.UnionMember;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.system.CommonMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.pb.DaFuWengPb;
import com.yanqu.road.server.pb.PlayerPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ZaoYaoLogic {

    /**
     * 【处理造谣事件】
     *
     * @return 错误码
     */
    public static int handleZaoYaoEvent(GamePlayer doPlayer, String unionUid) {
        DFWConfig config = DaFuWengMgr.getDfwConfig();
        DFWUserData userData = DaFuWengMgr.getUserData(config.getActivityInfo().getActivityId(), doPlayer.getUserId());
        if (userData.isComplete()) {
            return GameErrorCode.E_ACTIVITY_DFW_EVENT_HAD_HANDLE;
        }
        int eventId = userData.getEventId();
        Map<Integer, DFWEvent> dfwEventMap = config.getDfwEventMap();
        DFWEvent event = dfwEventMap.get(eventId);
        if (event == null) {
            DaFuWengMgr.getLogger().error("ZaoYaoLogic handleZaoYaoEvent can find event!");
            return GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR;
        }
        if (event.getEventType() != eDaFuWengEventType.ZaoYao) {
            return GameErrorCode.E_ACTIVITY_DFW_EVENT_TYPE_ERROR;
        }
        if (StringUtils.isNullOrEmpty(unionUid)) {
            return GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR;
        }
        // 没商会时，完成事件
        if (StringUtils.isNullOrEmpty(doPlayer.getUserInfo().getUnionUid())) {
            userData.setComplete(true);
            userData.setEventId(0);
            userData.setZaoYaoOptionalList(new ArrayList<>());
            DaFuWengMgr.syncDFWUserData(doPlayer);
            return GameErrorCode.E_ACTIVITY_DFW_NO_UNION;
        }
        // 无法选自己商会
        if (unionUid.equals(doPlayer.getUserInfo().getUnionUid())) {
            return GameErrorCode.E_ACTIVITY_DFW_CAN_NOT_SELF_UNION;
        }
        // 校验商会UID
        DFWZaoYaoOptional zaoYaoUnion = null;
        List<DFWZaoYaoOptional> zaoYaoUnionList = userData.getZaoYaoOptionalList();
        if (zaoYaoUnionList.isEmpty()) {
            DaFuWengMgr.getLogger().error("[fix] handle zao yao event error! can not find zaoYaoUnionList! event auto complete and no reward!");
            userData.setComplete(true);
            userData.setEventId(0);
            DaFuWengMgr.syncDFWUserData(doPlayer);
            return GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR;
        }
        for (DFWZaoYaoOptional tmpZaoYao : zaoYaoUnionList) {
            if (tmpZaoYao.getUnionUid().equals(unionUid)) {
                zaoYaoUnion = tmpZaoYao;
                break;
            }
        }
        if (zaoYaoUnion == null) {
            return GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR;
        }
        // 奖励
        Property reward = PropertyHelper.parseStringToProperty(event.getRewards());
        doPlayer.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.DaFuWeng, eLogMoneyType.DaFuWengZaoYaoReward);
        int gold = reward.getCountByGoodsId(eItemId.DFW_GOLDEN.getValue()).intValue();
        userData.setGoldScore(userData.getGoldScore() + gold);
        doPlayer.notifyListener(eGamePlayerEventType.DaFuWengScoreRank.getValue(), userData.getGoldScore());
        doPlayer.notifyListener(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL, BigInteger.valueOf(userData.getGoldScore()), doPlayer.getUserInfo().getUnionUid()));
        // 改状态
        userData.setComplete(true);
        userData.setEventId(0);
        // 判断区服维护
        if (isServerOpen(zaoYaoUnion.getBaseInfo().getServerId())) {
            MonopolyProto.CrossDfwHandleZaoYaoReqMsg.Builder msg = MonopolyProto.CrossDfwHandleZaoYaoReqMsg.newBuilder();
            msg.setActivityId(config.getActivityInfo().getActivityId());
            msg.setDoServerId(doPlayer.getUserInfo().getOriginalServerId());
            msg.setDoUserId(doPlayer.getUserId());
            msg.setRecordId(0);
            msg.setDoPlayer(DaFuWengPb.parseMonopolyPlayerMsg(doPlayer.getUserId(), PlayerPb.parsePlayerBaseTempMsg(doPlayer.getUserInfo()).build()));
            msg.setType(1);
            msg.setSelfUnionId(doPlayer.getUserInfo().getUnionUid());
            msg.setZaoyaoUnionId(unionUid);
            doPlayer.sendUnionActivityGroupPacket(Protocol.C_CROSS_DA_FU_WENG_HANDLE_ZAO_YAO, msg, config.getActivityInfo().getActivityId());
            userData.setZaoYaoOptionalList(new ArrayList<>());
            return 0;
        } else {
            userData.setZaoYaoOptionalList(new ArrayList<>());
            DaFuWengMgr.syncDFWUserData(doPlayer);
            return GameErrorCode.E_ACTIVITY_DFW_TARGET_SERVER_MAINTAIN;
        }
    }

    /**
     * 【处理造谣事件 返回】
     */
    public static void handleZaoYaoEventReturn(long userId, int result, MonopolyProto.ZaoYaoSceneMsg sceneMsg) {
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
        if (onlinePlayer != null) {
            // 造谣事件同步下数据直接返回
            DaFuWengMgr.syncDFWUserData(onlinePlayer);

            MonopolyProto.HandleRumorMakingEventRespMsg.Builder builder = MonopolyProto.HandleRumorMakingEventRespMsg.newBuilder();
            builder.setRet(result);
            if (result == 0) {
                builder.setSceneData(sceneMsg);
            }
            onlinePlayer.sendPacket(ClientProtocol.U_DA_FU_WENG_HANDLE_ZAO_YAO_EVENT, builder);
        }
    }

    /**
     * 【使用造谣卡造谣】
     */
    public static void useCardZaoYao(GamePlayer player, int index) {
        MonopolyProto.UseCardZaoYaoRespMsg.Builder respMsg = MonopolyProto.UseCardZaoYaoRespMsg.newBuilder();
        respMsg.setRet(0);
        String selfUnionUid = player.getUserInfo().getUnionUid();
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        // 判断自己有没有商会
        if (StringUtils.isNullOrEmpty(selfUnionUid)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_NO_UNION);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            return;
        }
        // 判断是否有造谣卡备选商会
        DFWUserData userData = DaFuWengMgr.getUserData(dfwConfig.getActivityInfo().getActivityId(), player.getUserId());
        if (userData.getZaoYaoCardOptionalList() == null || userData.getZaoYaoCardOptionalList().size() == 0) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_UNION_NO_FOUND);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            return;
        }
        // 判断是不是自身商会
        DFWZaoYaoOptional optional = userData.getZaoYaoCardOptionalList().get(index);
        if (optional.getUnionUid().equals(selfUnionUid)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_CAN_NOT_SELF_UNION);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            return;
        }
        // 判断是否维护
        if (!isServerOpen(optional.getBaseInfo().getServerId())) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_TARGET_SERVER_MAINTAIN);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            userData.setZaoYaoCardOptionalList(new ArrayList<>());
            return;
        }
        // 预扣除
        int zaoYaoCardId = getZaoYaoCardId(dfwConfig);
        Property property = new Property(zaoYaoCardId, BigInteger.ONE);
        if (!player.getModule(CurrencyModule.class).currencyIsEnough(property)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_ITEM_NO_ENOUGH);
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            return;
        }
        player.getModule(PreReduceModule.class).preReduce(zaoYaoCardId + "=1");
        // 处理造谣
   /*     MonopolyProto.CrossHandleZaoYaoReqMsg.Builder builder = DaFuWengPb.parseCrossHandleZaoYaoReqMsg(
                dfwConfig.getActivityInfo().getActivityId(),
                player.getUserInfo().getOriginalServerId(),
                player.getUserId(),
                optional.getUnionUid(),
                optional.getBaseInfo().getServerId(),
                DaFuWengPb.parseMonopolyPlayerMsg(player.getUserId(), PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()).build()),
                2);// 2：造谣卡造谣*/

        MonopolyProto.CrossDfwHandleZaoYaoReqMsg.Builder msg = MonopolyProto.CrossDfwHandleZaoYaoReqMsg.newBuilder();
        msg.setActivityId(dfwConfig.getActivityInfo().getActivityId());
        msg.setDoServerId(player.getUserInfo().getOriginalServerId());
        msg.setDoUserId(player.getUserId());
        msg.setRecordId(0);
        msg.setDoPlayer(DaFuWengPb.parseMonopolyPlayerMsg(player.getUserId(), PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()).build()));
        msg.setType(2);
        msg.setSelfUnionId(player.getUserInfo().getUnionUid());
        msg.setZaoyaoUnionId(optional.getUnionUid());
        player.sendUnionActivityGroupPacket(Protocol.C_CROSS_DA_FU_WENG_HANDLE_ZAO_YAO, msg, dfwConfig.getActivityInfo().getActivityId());
        // 刷新一下商会列表
        userData.setZaoYaoCardOptionalList(new ArrayList<>());
    }

    /**
     * 【使用造谣卡造谣 返回】
     */
    public static void useCardZaoYaoReturn(long userId, int result, MonopolyProto.ZaoYaoSceneMsg sceneMsg) {
        GamePlayer player = GamePlayerMgr.getPlayer(userId);
        if (player == null) {
            return;
        }
        MonopolyProto.UseCardZaoYaoRespMsg.Builder respMsg = MonopolyProto.UseCardZaoYaoRespMsg.newBuilder();
        respMsg.setRet(result);
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        int zaoYaoCardId = getZaoYaoCardId(dfwConfig);
        // 恢复预扣除
        player.getModule(PreReduceModule.class).restorePreReduce(zaoYaoCardId + "=1");
        // 如果造谣失败
        if (result != 0) {
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
            return;
        }
        // 消耗造谣卡
        consumeZaoYaoCard(player, eLogMoneyType.DaFuWengUseCardCost);
        // 同步数据
        DaFuWengMgr.syncDFWUserData(player);
        // 返回
        respMsg.setSceneData(sceneMsg);
        player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD_ZAO_YAO, respMsg);
    }

    /**
     * 【使用造谣卡反击】
     *
     * @param param 造谣记录ID
     * @return 是否通过使用校验
     */
    public static boolean useZaoYaoCardStrikeBack(GamePlayer player, String param, MonopolyProto.UseCardRespMsg.Builder respMsg) {
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        // 看看自己是否有商会
        String selfUnionUid = player.getUserInfo().getUnionUid();
        if (StringUtils.isNullOrEmpty(selfUnionUid)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_NO_UNION);
            return false;
        }
        // 拿造谣记录ID
        int recordId;
        try {
            recordId = Integer.valueOf(param);
        } catch (Exception e) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR);
            return false;
        }
  /*      // 找对应造谣记录
        List<DFWUnionRecord> unionRecordList = DaFuWengMgr.getUnionRecord(dfwConfig.getActivityInfo().getActivityId(), selfUnionUid, 1);
        DFWUnionRecord record = null;
        for (DFWUnionRecord tmpRecord : unionRecordList) {
            if (tmpRecord.getRecordId() == recordId) {
                record = tmpRecord;
                break;
            }
        }
        if (record == null) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR);
            return false;
        }
        // 判断是不是自身商会
        if (record.getUserBaseInfo().getUnionUid().equals(selfUnionUid)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_CAN_NOT_SELF_UNION);
            return false;
        }
        // 判断是否维护
        if (!isServerOpen(record.getUserBaseInfo().getServerId())) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_TARGET_SERVER_MAINTAIN);
            return false;
        }
        // 反击次数判断
        int beatBackTimes = record.getBeatBackTimes();
        if (beatBackTimes >= dfwConfig.getUnionBeatBackTimes()) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_ZAO_YAO_TIMES_NO_ENOUGH);
            return false;
        }*/
        // 预扣除
        int zaoYaoCardId = getZaoYaoCardId(dfwConfig);
        Property property = new Property(zaoYaoCardId, BigInteger.ONE);
        if (!player.getModule(CurrencyModule.class).currencyIsEnough(property)) {
            respMsg.setRet(GameErrorCode.E_ACTIVITY_DFW_ITEM_NO_ENOUGH);
            return false;
        }
        player.getModule(PreReduceModule.class).preReduce(zaoYaoCardId + "=1");
        // 扣反击次数
        // 跨服处理造谣
        MonopolyProto.CrossDfwHandleZaoYaoReqMsg.Builder msg = MonopolyProto.CrossDfwHandleZaoYaoReqMsg.newBuilder();
        msg.setActivityId(dfwConfig.getActivityInfo().getActivityId());
        msg.setDoServerId(player.getUserInfo().getOriginalServerId());
        msg.setDoUserId(player.getUserId());
        msg.setRecordId(recordId);
        msg.setDoPlayer(DaFuWengPb.parseMonopolyPlayerMsg(player.getUserId(), PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()).build()));
        msg.setType(3);
        msg.setSelfUnionId(selfUnionUid);
        /*MonopolyProto.CrossDfwHandleZaoYaoReqMsg.Builder builder = DaFuWengPb.parseCrossHandleZaoYaoReqMsg(
                dfwConfig.getActivityInfo().getActivityId(),
                player.getUserInfo().getOriginalServerId(),
                player.getUserId(),
                record.getUserBaseInfo().getUnionUid(),
                record.getUserBaseInfo().getServerId(),
                DaFuWengPb.parseMonopolyPlayerMsg(player.getUserId(), PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()).build()),
                3);*/
        player.sendUnionActivityGroupPacket(Protocol.C_CROSS_DA_FU_WENG_HANDLE_ZAO_YAO, msg, dfwConfig.getActivityInfo().getActivityId());
        // 返回（并不会返回使用卡片结果）
        respMsg.setRet(0);
        return true;
    }

    /**
     * 【使用造谣卡反击 返回】
     */
    public static void useZaoYaoCardStrikeBackReturn(long userId, int result, MonopolyProto.ZaoYaoSceneMsg sceneMsg, String unionUid) {
        GamePlayer player = GamePlayerMgr.getPlayer(userId);
        if (player == null) {
            return;
        }
        MonopolyProto.UseCardRespMsg.Builder respMsg = MonopolyProto.UseCardRespMsg.newBuilder();
        respMsg.setRet(result);
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        int zaoYaoCardId = getZaoYaoCardId(dfwConfig);
        // 恢复预扣除
        player.getModule(PreReduceModule.class).restorePreReduce(zaoYaoCardId + "=1");
        // 如果造谣失败
        if (result != 0) {
            List<DFWUnionRecord> recordList = DaFuWengMgr.getUnionRecord(dfwConfig.getActivityInfo().getActivityId(), player.getUserInfo().getUnionUid(), 1);
            // 把解散的商会的造谣记录，反击次数清空
            for (DFWUnionRecord unionRecord : recordList) {
                if (unionRecord.getUserBaseInfo().getUnionUid().equals(unionUid)) {
                    unionRecord.setBeatBackTimes(dfwConfig.getUnionBeatBackTimes());
                }
            }
            player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD, respMsg);
            return;
        }
        // 消耗造谣卡
        consumeZaoYaoCard(player, eLogMoneyType.DaFuWengUseCardCost);
        // 同步数据
        DaFuWengMgr.syncDFWUserData(player);
        // 返回
        respMsg.setSceneData(sceneMsg);
        player.sendPacket(ClientProtocol.U_DA_FU_WENG_USE_CARD, respMsg);
    }

    // ==========================================================================================

    /**
     * 本服处理来自跨服的造谣
     *
     * @return 错误码
     */
    public static int zaoYaoFromCross(String unionUid, int activityId, MonopolyProto.MonopolyPlayerMsg doPlayer, MonopolyProto.ZaoYaoSceneMsg.Builder sceneMsg) {
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        // 判断商会是否存在
        UnionInfo unionInfo = CrossUnionMgr.getUnionInfo(unionUid);
        Map<Long, CrossUnionMember> unionMemberMap = CrossUnionMgr.getUnionMemberMap(unionUid);
        if (unionInfo == null || unionInfo.isDelete() || unionMemberMap == null) {
            return GameErrorCode.E_ACTIVITY_DFW_UNION_DELETE;
        }
        // 加造谣记录
     //   DaFuWengMgr.addUnionRecord(unionUid, activityId, doPlayer, 1);
        // 修改加成
     //   DFWUnionData unionData = DaFuWengMgr.getUnionData(activityId, unionUid);
    //    DaFuWengMgr.changeAddition(dfwConfig.getZaoYaoAddition(), unionData);
        // 给商会成员同步造谣动画
        List<UnionMember> memberList = new ArrayList<>(unionMemberMap.values());
        for (UnionMember member : memberList) {
            GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(member.getUserId());
            if (onlinePlayer == null) {
                continue;
            }
            MonopolyProto.SyncZaoYaoRespMsg.Builder builder = MonopolyProto.SyncZaoYaoRespMsg.newBuilder();
            builder.setName(doPlayer.getPlayer().getNickName());
            onlinePlayer.sendPacket(ClientProtocol.U_DA_FU_WENG_SYNC_ZAO_YAO, builder);
        }

        return 0;
    }

    /**
     * 跨服返回造谣处理结果
     *
     * @param result 0成功，1解散
     * @param type   1造谣事件，2造谣卡造谣，3造谣卡反击
     */
    public static void zaoYaoResultFromCross(long userId, int type, int result, MonopolyProto.ZaoYaoSceneMsg sceneData, String unionUid) {
        // 根据类型返回
        if (type == 1) {
            handleZaoYaoEventReturn(userId, result, sceneData);
        } else if (type == 2) {
            useCardZaoYaoReturn(userId, result, sceneData);
        } else if (type == 3) {
            useZaoYaoCardStrikeBackReturn(userId, result, sceneData, unionUid);
        }
    }

    /**
     * 消耗一张造谣卡，获得对应奖励
     *
     * @return 是否成功
     */
    public static boolean consumeZaoYaoCard(GamePlayer player, eLogMoneyType childType) {
        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
        int zaoYaoCardId = getZaoYaoCardId(dfwConfig);
        DFWUserData userData = DaFuWengMgr.getUserData(dfwConfig.getActivityInfo().getActivityId(), player.getUserId());
        // 获取使用造谣卡奖励
        Property reward = new Property();
        GoodsInfo goodsInfo = CommonMgr.getGoodsInfo(zaoYaoCardId);
        if (goodsInfo != null) {
            try {
                int eventId = Integer.parseInt(goodsInfo.getExtendParam().split(";")[0]);
                reward = PropertyHelper.parseStringToProperty(dfwConfig.getDfwEventMap().get(eventId).getRewards());
            } catch (Exception e) {
                DaFuWengMgr.getLogger().error("DaFuWengMgr useZaoYaoCardStrikeBackReturn zaoYaoCard goods param error!!");
            }
        }
        // 扣道具
        player = GamePlayerMgr.getPlayer(player.getUserId());
        if (!player.getModule(CurrencyModule.class).removeCurrency(new Property(zaoYaoCardId, BigInteger.ONE), eLogMoneyType.DaFuWeng, childType)) {
            return false;
        }
        // 加奖励
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.DaFuWeng, eLogMoneyType.DaFuWengZaoYaoReward);
        int gold = reward.getCountByGoodsId(eItemId.DFW_GOLDEN.getValue()).intValue();
        userData.setGoldScore(userData.getGoldScore() + gold);
        player.notifyListener(eGamePlayerEventType.DaFuWengScoreRank.getValue(), userData.getGoldScore());
        player.notifyListener(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_NORMAL, BigInteger.valueOf(userData.getGoldScore()), player.getUserInfo().getUnionUid()));
        return true;
    }

    /**
     * 获取造谣卡ID
     */
    public static int getZaoYaoCardId(DFWConfig dfwConfig) {
        for (Map.Entry<Integer, eDaFuWengCardType> entry : dfwConfig.getCardConfigMap().entrySet()) {
            if (entry.getValue() == eDaFuWengCardType.YaoYan) {
                return entry.getKey();
            }
        }
        DaFuWengMgr.getLogger().error("can not find zao yao card id!");
        return 120135;
    }

    /**
     * 对方服务器是否正常
     */
    public static boolean isServerOpen(long serverId) {
        ServerInfo serverInfo = ServerListMgr.getServerInfo(serverId);
        if (serverInfo == null) {
            return false;
        }
        return serverInfo.getState() == eServerState.Normal.getValue();
    }
}
